//
// Created by 董一龙 on 2022/10/13.
//

#include "fqueue/segment_queue/mmap_queue/buffer/memory_map_buffer.h"

namespace fqueue {
    memory_map_buffer::memory_map_buffer(std::filesystem::path const& filename, size_t mmap_size) : buffer{} {
        if (!platform::exists(filename.c_str())) {
            platform::create_file(filename.c_str(), mmap_size);
        }
        m_pMmapObj = std::make_unique<mmaplib::mmap>(filename.c_str(), mmap_size);
    }

    [[nodiscard]] uint8_t * memory_map_buffer::data() const  {
        return static_cast<uint8_t *>(m_pMmapObj->data());
    }
    [[nodiscard]] size_t memory_map_buffer::size() const  {
        return m_pMmapObj->size();
    };
} // fqueue

